<template>
  <div ref="matrixTableWrapper" class="matrix-table-wrapper">
    <table ref="matrixTable" class="matrix-table not-print">
      <thead>
        <tr v-if="matrixLayout.columns">
          <td style="width: 150px" />
          <td v-for="column in matrixLayout.columns" :key="column.id">
            {{ column.label }}
          </td>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(row,key) in value" :key="row+key">
          <td style="width: 150px">
            {{ key }}
          </td>
          <td v-for="(item,key2) in row" :key="item+key+key2">
            <div>
              <div v-if="Array.isArray(item)">
                <div v-if="item[0] && item[0].name" class="file-list-wrapper">
                  <ul class="el-upload-list el-upload-list--text">
                    <li v-for="(f,index) in item" :key="index" tabindex="0" class="el-upload-list__item is-success">
                      <a class="el-upload-list__item-name" :href="f.url" target="_blank">
                        <i class="el-icon-document" />{{ f.name }}
                      </a>
                      <label class="el-upload-list__item-status-label">
                        <i class="el-icon-upload-success el-icon-circle-check" />
                      </label>
                    </li>
                  </ul>
                </div>
                <div v-else>
                  <div slot="reference">
                    <span v-for="v in item" :key="v.label+v.value">{{ v.label }} </span>
                  </div>
                </div>
              </div>
              <div v-else-if="typeof(item) == 'object' && item instanceof Object">
                {{ item.label }}
              </div>
              <div v-else>
                {{ item }}
              </div>
            </div>
          </td>
        </tr>
      </tbody>
    </table>
    <div ref="matrixTablePrintWrapper" class="matrix-table-print-wrapper print" />
  </div>
</template>

<script>
export default {
  name: "MatrixView",
  props: {
    type: {
      type: String,
      default: ''
    },
    value: {
      type: Object,
      default: () => {
      }
    },
    matrixLayout: {
      type: Object,
      default: () => {
      }
    }
  },
  mounted() {
    console.log(this.matrixLayout,'matrixLayout')
    console.log(this.value,'value')
    let table = this.$refs.matrixTable.cloneNode(true)
    table.className = 'matrix-table-print'
    this.$refs.matrixTablePrintWrapper.appendChild(table)
  }
}
</script>

<style lang="scss" scoped>
.matrix-table-wrapper {
  overflow: scroll;
}

.matrix-table {
  font-size: 11px;
  color: #303133;
  border-width: 1px;
  border-color: #DCDFE6;
  border-collapse: collapse;
  min-width: 90%;
  //display: none;
}

.matrix-table td {
  border-width: 1px;
  padding: 8px;
  border-style: solid;
  border-color: #DCDFE6;
  background-color: #ffffff;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.print{
  display: none;
}


.matrix-table-print {
  font-family: Arial, sans-serif;
  background-color: #ffffff;
  table-layout: auto;
  width: 100%;
  font-size: 11px;
  color: #303133;
  border-width: 1px;
  border-color: #DCDFE6;
  border-collapse: collapse;

  thead {
    border-top-width: 1px;
    border-top-style: solid;
    border-top-color: #dadcde;
    line-height: 40px;
    font-weight: bold;
    color: #454c70;
  }

  tr {
    border-top-width: 1px;
    border-top-style: solid;
    border-top-color: #dadcde;
    line-height: 23px;
  }

  td {
    padding: 5px 10px;
    font-size: 14px;
    width: 100px;
    border-width: 1px;
    border-style: solid;
    border-color: #DCDFE6;
    background-color: #ffffff;
    word-break: break-all;
  }

}
</style>


